// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "Character/BaseCharacter.h"
#include "Interaction/EnemyInterface.h"
#include "EnemyCharacter.generated.h"

class AAuraAIController;
class UBehaviorTree;
struct FGameplayTag;
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnAttributeChangedSignature, float, NewValue);

class UWidgetComponent;
/**
 * 敌人类
 */
UCLASS()
class AURA_API AEnemyCharacter : public ABaseCharacter, public IEnemyInterface
{
	GENERATED_BODY()

public:

	AEnemyCharacter();

	// ----------------------------------------------------------------------------------------------------------------
	//	属性相关
	// ----------------------------------------------------------------------------------------------------------------

	/** 生命值变化委托 */
	UPROPERTY(BlueprintAssignable)
	FOnAttributeChangedSignature OnHealthChanged;

	/** 最大生命值变化委托 */
	UPROPERTY(BlueprintAssignable)
	FOnAttributeChangedSignature OnMaxHealthChanged;

	// ----------------------------------------------------------------------------------------------------------------
	//	战斗相关
	// ----------------------------------------------------------------------------------------------------------------

	/** 战斗目标 */
	UPROPERTY()
	TObjectPtr<AActor> CombatTarget;

	// ----------------------------------------------------------------------------------------------------------------
	//	IEnemyInterface接口实现
	// ----------------------------------------------------------------------------------------------------------------
	virtual void ShouldHighlightActor(bool bHighlight) override;
	virtual AActor* GetCombatTarget_Implementation() const override;
	virtual void SetCombatTarget_Implementation(AActor* InCombatTarget) override;

	// ----------------------------------------------------------------------------------------------------------------
	//	ICombatInterface接口实现
	// ----------------------------------------------------------------------------------------------------------------


	/** 敌人死亡实现 */
	virtual void Die() override;

	// ----------------------------------------------------------------------------------------------------------------
	//	其他
	// ----------------------------------------------------------------------------------------------------------------
	virtual void PossessedBy(AController* NewController) override;

protected:

	virtual void BeginPlay() override;

	// ----------------------------------------------------------------------------------------------------------------
	//	AI相关
	// ----------------------------------------------------------------------------------------------------------------

	/** 行为树指针 */
	UPROPERTY(EditAnywhere, Category="EnemyCharacter|AI")
	TObjectPtr<UBehaviorTree> BehaviorTree;

	/** AI控制器指针 */
	UPROPERTY()
	TObjectPtr<AAuraAIController> AuraAIController;

	// ----------------------------------------------------------------------------------------------------------------
	//	UI相关
	// ----------------------------------------------------------------------------------------------------------------

	/** 生命条控件组件指针 */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="EnemyCharacter|Widget", meta=(AllowPrivateAccess))
	TObjectPtr<UWidgetComponent> HealthBar;

private:

	// ----------------------------------------------------------------------------------------------------------------
	//	战斗相关
	// ----------------------------------------------------------------------------------------------------------------

	/** 当前角色的最大移动速度 */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="EnemyCharacter|Combat", meta=(AllowPrivateAccess))
	float BaseWalkSpeed = 250.f; 
	

	/* 设置死亡后的存在时间 */
	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="EnemyCharacter|Combat", meta=(AllowPrivateAccess))
	float LifePan = 5.0;
	

	/** 当前是否处于被攻击状态 */
	UPROPERTY(BlueprintReadOnly, Category="EnemyCharacter|Combat", meta=(AllowPrivateAccess))
	bool bHitReacting = false;

	/** 受击标签变化回调 */
	void OnHitReactTagChanged(const FGameplayTag CallbackTag, int32 NewCount);

	// ----------------------------------------------------------------------------------------------------------------
	//	初始化相关
	// ----------------------------------------------------------------------------------------------------------------

	/** 初始化ASC相关信息 */
	virtual void InitAbilityActorInfo() override;

	/** 初始化默认属性 */
	virtual void InitDefaultAttributes() const override;
};
